import Vue from "vue";
import App from "./App.vue";
// import "./registerServiceWorker";
import createRouter from "./router";
import createStore from "./store";

Vue.config.productionTip = false;

Vue.directive("money", {
  inserted: function (el, binding, vnode) {
    console.log(123);
    el.addEventListener("blur", function (e) {
      let val = e.target.value;
      const { modifiers } = binding;
      if (modifiers.int) {
        val = parseInt(val);
      } else if (modifiers.float) {
        val = parseFloat(val);
      }
      val = !isNaN(val) ? val : "";
      if (vnode.data.model) {
        vnode.data.model = vnode.data.model.callback(val);
      } else {
        e.target.value = val;
      }
    });
  },
});

Vue.mixin({
  beforeMount() {
    const { asyncData } = this.$options;
    if (asyncData) {
      // 将获取数据操作分配给 promise
      // 以便在组件中，我们可以在数据准备就绪后
      // 通过运⾏ `this.dataPromise.then(...)` 来执⾏其他任务
      // this.dataPromise = asyncData({
      //   store: this.$store,
      //   route: this.$route,
      // });
    }
  },
});

export function createApp() {
  const router = createRouter();
  const store = createStore();
  const app = new Vue({
    router,
    store,
    render: (h) => h(App),
  });
  //.$mount("#app");
  return { app, router, store };
}
